﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using Medianamik.Core;
using Medianamik.Globalization;
using Medianamik.UI.Controls;

namespace Medianamik.UI.ConfigManagement
{
    public partial class ModuleManagement : BaseModuleEditionPage<MedianamikModule>
    {
        protected const string LIST_PAGE = "PageList.aspx?tab=0";

        protected override void Save(object sender, EventArgs e)
        {
            if (IsValid)
            {
                var module = MedianamikFormTemplate.GetFormValue(CurrentNode);

                NodeManager.SaveNode(module);

                Translator.CreateResource("SiteMap", CurrentNode.Alias, module.GetValues<String>("Name"));

                //Reset du Menu
                ((MedianamikSiteMapProvider) SiteMap.Provider).Rebuild();

                Response.Redirect(ReturnURL);
            }
        }

        protected override string ReturnURL
        {
            get { return LIST_PAGE; }
        }

        public override MedianamikFormTemplate MedianamikFormTemplate
        {
            get { return Fields; }
        }

        public override Guid? TypeId
        {
            get { return MedianamikTypes.Module; }
        }

        public override LinkButton SaveButton
        {
            get { return btnSave; }
        }

        protected override Guid? ParentNodeId
        {
            get { return null; }
        }
    }
}